$(document).ready(function() {

    (function() {
        // 每间隔一秒刷新时间
    setInterval("gettime()", 1000);
    
    //获取时间02
    window.gettime = function GetTime() {
        var mon, day, now, hour, min, ampm, time, str, tz, end, beg, sec;
        /*
        mon = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
                "Sep", "Oct", "Nov", "Dec");
        */
        mon = new Array("一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月",
                "九月", "十月", "十一月", "十二月");
        /*
        day = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
        */
        day = new Array("周日", "周一", "周二", "周三", "周四", "周五", "周六");
        now = new Date();
        hour = now.getHours();
        min = now.getMinutes();
        sec = now.getSeconds();
        if (hour < 10) {
            hour = "0" + hour;
        }
        if (min < 10) {
            min = "0" + min;
        }
        if (sec < 10) {
            sec = "0" + sec;
        }
        $("#Timer").html(
            now.getFullYear() + "年" + (now.getMonth() + 1) + "月" + now.getDate() + "日" + "  " + hour + ":" + min + ":" + sec
            );
    }
    })();    

    //当前系统时间【ibase4j中的方法】
    (function(){
        setInterval(show_cur_times, 100);

        function show_cur_times() {
            if(document.getElementById("showtimes")) {
                //获取当前日期
                var date_time = new Date();
                //定义星期
                var week;
                //switch判断
                switch (date_time.getDay()) {
                    case 1:
                        week = "星期一";
                        break;
                    case 2:
                        week = "星期二";
                        break;
                    case 3:
                        week = "星期三";
                        break;
                    case 4:
                        week = "星期四";
                        break;
                    case 5:
                        week = "星期五";
                        break;
                    case 6:
                        week = "星期六";
                        break;
                    default:
                        week = "星期天";
                        break;
                }
    
                //年
                var year = date_time.getFullYear();
                //判断小于10，前面补0
                if (year < 10) {
                    year = "0" + year;
                }
    
                //月
                var month = date_time.getMonth() + 1;
                //判断小于10，前面补0
                if (month < 10) {
                    month = "0" + month;
                }
    
                //日
                var day = date_time.getDate();
                //判断小于10，前面补0
                if (day < 10) {
                    day = "0" + day;
                }
    
                //时
                var hours = date_time.getHours();
                //判断小于10，前面补0
                if (hours < 10) {
                    hours = "0" + hours;
                }
    
                //分
                var minutes = date_time.getMinutes();
                //判断小于10，前面补0
                if (minutes < 10) {
                    minutes = "0" + minutes;
                }
    
                //秒
                var seconds = date_time.getSeconds();
                //判断小于10，前面补0
                if (seconds < 10) {
                    seconds = "0" + seconds;
                }
    
                //拼接年月日时分秒
                var date_str = year + "年" + month + "月" + day + "日 " + hours + ":" + minutes + ":" + seconds;
    
                //显示在id为showtimes的容器里
                document.getElementById("showtimes").innerHTML = date_str;
            }
        }
    })();
    
    
    (function($){
        $.formatDate = function(pattern,date){
            //假设不设置，默觉得当前时间
            if(!date) date = new Date();
            if(typeof(date) ==="string"){
                 if(date=="")  date = new Date();
                  else  date = new Date(date.replace(/-/g,"/"));
            }   
            /*补00*/
            var toFixedWidth = function(value){
                 var result = 100+value;
                 return result.toString().substring(1);
            };
            
            /*配置*/
            var options = {
                    regeExp:/(yyyy|M+|d+|h+|m+|s+|ee+|ws?|p)/g,
                    months: ['January','February','March','April','May',
                             'June','July', 'August','September',
                              'October','November','December'],
                    weeks: ['Sunday','Monday','Tuesday',
                            'Wednesday','Thursday','Friday',
                                'Saturday']
            };
            
            /*时间切换*/
            var swithHours = function(hours){
                return hours < 12 ? "AM" : "PM";
            };
            
            /*配置值*/
            var pattrnValue = {
                    "yyyy":date.getFullYear(),                      //年份
                    "MM":toFixedWidth(date.getMonth()+1),           //月份
                    "dd":toFixedWidth(date.getDate()),              //日期
                    "hh":toFixedWidth(date.getHours()),             //小时
                    "mm":toFixedWidth(date.getMinutes()),           //分钟
                    "ss":toFixedWidth(date.getSeconds()),           //秒
                    "ee":options.months[date.getMonth()],           //月份名称
                    "ws":options.weeks[date.getDay()],              //星期名称
                    "M":date.getMonth()+1,
                    "d":date.getDate(),
                    "h":date.getHours(),
                    "m":date.getMinutes(),
                    "s":date.getSeconds(),
                    "p":swithHours(date.getHours())
            };
            
            return pattern.replace(options.regeExp,function(){
                   return  pattrnValue[arguments[0]];
            });
        };
        
    })($);

    
});